//
//  BJLianZhengJiaoYuViewController.m
//  DangXiao
//
//  Created by APPLE on 16/12/6.
//  Copyright © 2016年 APPLE. All rights reserved.
//

#import "BJLianZhengJiaoYuViewController.h"
#import "BJHeaderView.h"
#import "BJShiZhengYaoWenTableViewCell.h"
#import "BJTipHeaderTableViewCell.h"
#import "BJJingPinKeTangTabelViewCell.h"

@interface BJLianZhengJiaoYuViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *myTableView;

@end

@implementation BJLianZhengJiaoYuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"廉政教育";
}

#pragma mark ---- 设置TbaleView
- (void)initUI{
    
    BJHeaderView *VIEW = [[BJHeaderView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, BILIHEIGHT(280))];
    
    _myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - 64) style:(UITableViewStylePlain)];
    _myTableView.delegate = self;
    _myTableView.dataSource = self;
    _myTableView.backgroundColor = GrayLabel;
    _myTableView.tableHeaderView = VIEW;
    //    注册cell
    [_myTableView registerClass:[BJShiZhengYaoWenTableViewCell class] forCellReuseIdentifier:@"BJShiZhengYaoWenTableViewCell"];
    
    [_myTableView registerClass:[BJJingPinKeTangTabelViewCell class] forCellReuseIdentifier:@"BJJingPinKeTangTabelViewCell"];
    
    [self.view addSubview:_myTableView];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 4;
    }else{
    return 1;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        BJShiZhengYaoWenTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BJShiZhengYaoWenTableViewCell" forIndexPath:indexPath];
        return cell;
    }else{
        BJJingPinKeTangTabelViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BJJingPinKeTangTabelViewCell" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return BILIHEIGHT(90);
 
    }else{
        return BILIHEIGHT(180 * 2);
    }
}

static BJTipHeaderTableViewCell *cellView;
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
        cellView  = [[BJTipHeaderTableViewCell alloc]init];
        cellView.backgroundColor = GrayLabel;
    if (section == 0) {
        cellView.nameLabel.text = @"图文";
    }else{
        cellView.nameLabel.text = @"视频";
    }
//        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(didTapView:section:)];
//        [cellView addGestureRecognizer:tap];
        return cellView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return BILIHEIGHT(39);
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView == self.myTableView)
    {
        CGFloat sectionHeaderHeight = BILIHEIGHT(39); //区头高度
        if (scrollView.contentOffset.y <= sectionHeaderHeight&&scrollView.contentOffset.y >=0) {
            scrollView.contentInset = UIEdgeInsetsMake(- scrollView.contentOffset.y, 0, 0, 0);
        } else if (scrollView.contentOffset.y >= sectionHeaderHeight) {
            scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
        }
    }
}

- (void)viewDidAppear:(BOOL)animated{
    self.navigationController.navigationBar.translucent = NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
